package com.cakeclient;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import com.actionbarsherlock.app.SherlockFragment;
import com.cakeclient.Model.Basket;
import com.cakeclient.Model.Client;
import com.cakeclient.Model.Gender;

public class ClientRegisterFragment extends SherlockFragment{
    private ViewGroup container;
    private Bundle savedInstanceState;
    private Client client = new Client();
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        this.container = container;
        this.savedInstanceState = savedInstanceState;
        return inflater.inflate(R.layout.client_register_form,container,false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        RadioButton radioMale = (RadioButton) getSherlockActivity().findViewById(R.id.radio_male);
        radioMale.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                client.setSex(Gender.MALE);
            }
        });
        RadioButton radioFemale = (RadioButton) getSherlockActivity().findViewById(R.id.radio_female);
        radioFemale.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                client.setSex(Gender.FEMALE);
            }
        });

        Button buttonNext = (Button) getSherlockActivity().findViewById(R.id.client_register_continue_button);
        buttonNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                LaunchRegisterSecondPart();
            }
        });
    }


    public void LaunchRegisterSecondPart(){
        EditText nameEditText = (EditText) getSherlockActivity().findViewById(R.id.client_register_name_edittext);
        EditText firstNameEditText = (EditText) getSherlockActivity().findViewById(R.id.client_register_firstname_edittext);
        EditText phoneNumberEditText = (EditText) getSherlockActivity().findViewById(R.id.client_register_phonenumber_edittext);

        client.setFirstName(firstNameEditText.getText().toString());
        client.setName(nameEditText.getText().toString());
        client.setPhoneNumber(phoneNumberEditText.getText().toString());
        ((MainParametersActivity)getSherlockActivity()).LaunchRegister2Fragment(client);

    }

}
